package entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Francis
 */
@Entity
@Table(name = "person")
@NamedQueries({@NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"), @NamedQuery(name = "Person.findByPersonID", query = "SELECT p FROM Person p WHERE p.personID = :personID"), @NamedQuery(name = "Person.findByLoginname", query = "SELECT p FROM Person p WHERE p.loginname = :loginname"), @NamedQuery(name = "Person.findByPassword", query = "SELECT p FROM Person p WHERE p.password = :password"), @NamedQuery(name = "Person.findByFirstname", query = "SELECT p FROM Person p WHERE p.firstname = :firstname"), @NamedQuery(name = "Person.findByLastname", query = "SELECT p FROM Person p WHERE p.lastname = :lastname"), @NamedQuery(name = "Person.findByEmail", query = "SELECT p FROM Person p WHERE p.email = :email"), @NamedQuery(name = "Person.findByGender", query = "SELECT p FROM Person p WHERE p.gender = :gender"), @NamedQuery(name = "Person.findByBirthYear", query = "SELECT p FROM Person p WHERE p.birthYear = :birthYear"), @NamedQuery(name = "Person.findByBirthMonth", query = "SELECT p FROM Person p WHERE p.birthMonth = :birthMonth"), @NamedQuery(name = "Person.findByAddress", query = "SELECT p FROM Person p WHERE p.address = :address"), @NamedQuery(name = "Person.findByMailPromotion", query = "SELECT p FROM Person p WHERE p.mailPromotion = :mailPromotion"), @NamedQuery(name = "Person.findByRegtertime", query = "SELECT p FROM Person p WHERE p.regtertime = :regtertime"), @NamedQuery(name = "Person.findByRegterIP", query = "SELECT p FROM Person p WHERE p.regterIP = :regterIP"), @NamedQuery(name = "Person.findByActivated", query = "SELECT p FROM Person p WHERE p.activated = :activated"), @NamedQuery(name = "Person.findByRating", query = "SELECT p FROM Person p WHERE p.rating = :rating") //new queries
    , @NamedQuery(name = "Person.login", query = "SELECT p FROM Person p WHERE p.loginname =:loginname AND p.password = :password"),
    @NamedQuery(name = "Person.updatePassword", query = "UPDATE Person p SET p.password = :newPass WHERE p.password = :oldPass AND p.personID = :personID"),
    @NamedQuery(name = "Person.updateInformation", query = "UPDATE Person p SET p.email = :email,  p.address = :address, p.birthYear = :birthYear, p.birthMonth = :birthMonth WHERE p.personID = :personID")
})
public class Person implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "personID", nullable = false)
    private Integer personID;
    @Basic(optional = false)
    @Column(name = "loginname", nullable = false, length = 50)
    private String loginname;
    @Basic(optional = false)
    @Column(name = "password", nullable = false, length = 50)
    private String password;
    @Column(name = "firstname", length = 50)
    private String firstname;
    @Column(name = "lastname", length = 50)
    private String lastname;
    @Basic(optional = false)
    @Column(name = "email", nullable = false, length = 50)
    private String email;
    @Column(name = "gender", length = 50)
    private String gender;
    @Column(name = "birth_year")
    private Integer birthYear;
    @Column(name = "birth_month")
    private Integer birthMonth;
    @Column(name = "address", length = 50)
    private String address;
    @Basic(optional = false)
    @Column(name = "mailPromotion", nullable = false)
    private boolean mailPromotion;
    @Basic(optional = false)
    @Column(name = "regtertime", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date regtertime;
    @Column(name = "regterIP")
    private String regterIP;
    @Basic(optional = false)
    @Column(name = "activated", nullable = false)
    private boolean activated;
    @Column(name = "rating")
    private Integer rating;
    @Column(name = "msn")
    private String msn;
    
    //customize properties
    @OneToMany(fetch= FetchType.LAZY, mappedBy = "person")
    private List<Book> books;

    public Person() {
    }

    public Person(Integer personID) {
        this.personID = personID;
    }

    public Person(Integer personID, String loginname, String password, String email, boolean mailPromotion, Date regtertime, boolean activated) {
        this.personID = personID;
        this.loginname = loginname;
        this.password = password;
        this.email = email;
        this.mailPromotion = mailPromotion;
        this.regtertime = regtertime;
        this.activated = activated;
    }

    public Integer getPersonID() {
        return personID;
    }

    public void setPersonID(Integer personID) {
        this.personID = personID;
    }

    public String getLoginname() {
        return loginname;
    }

    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getBirthYear() {
        return birthYear;
    }

    public void setBirthYear(Integer birthYear) {
        this.birthYear = birthYear;
    }

    public Integer getBirthMonth() {
        return birthMonth;
    }

    public void setBirthMonth(Integer birthMonth) {
        this.birthMonth = birthMonth;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public boolean getMailPromotion() {
        return mailPromotion;
    }

    public void setMailPromotion(boolean mailPromotion) {
        this.mailPromotion = mailPromotion;
    }

    public Date getRegtertime() {
        return regtertime;
    }

    public void setRegtertime(Date regtertime) {
        this.regtertime = regtertime;
    }

    public String getRegterIP() {
        return regterIP;
    }

    public void setRegterIP(String regterIP) {
        this.regterIP = regterIP;
    }

    public boolean getActivated() {
        return activated;
    }

    public void setActivated(boolean activated) {
        this.activated = activated;
    }

    public Integer getRating() {
        return rating;
    }

    public void setRating(Integer rating) {
        this.rating = rating;
    }

    public String getMsn() {
        return msn;
    }

    public void setMsn(String msn) {
        this.msn = msn;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (personID != null ? personID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.personID == null && other.personID != null) || (this.personID != null && !this.personID.equals(other.personID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Person[personID=" + personID + "]";
    }

    //customize properties
    public List<Book> getBooks() {
        return books;
    }
    
}
